#include "ExponentialFunction.h"
#include "../Helper.h"
#include <math.h>

using namespace NeuralPlusPlus::Core;

NeuralPlusPlus::Core::LearningRateFunctions::ExponentialFunction::ExponentialFunction( double initialLearningRate, double finalLearningRate ) : AbstractFunction(initialLearningRate, finalLearningRate)
	{
	logFinalByInitial
		= log(max(InitialLearningRate, InitialLearningRate + 1e-4)
		/ max(FinalLearningRate, FinalLearningRate + 1e-4));
	}

double NeuralPlusPlus::Core::LearningRateFunctions::ExponentialFunction::GetLearningRate( int currentIteration, int trainingEpochs )
	{
	Helper::ValidatePositive(trainingEpochs, "trainingEpochs");
	Helper::ValidateWithinRange(currentIteration, 0, trainingEpochs - 1, "currentIteration");

	return InitialLearningRate * exp((logFinalByInitial * currentIteration) / trainingEpochs);
	}